package flst.ipiweb.persistance.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class JdbcUtils {
	
	private static JdbcUtils instance = null;
	private static final String BDD_URL = "jdbc:h2:tcp://localhost//C:/Dev/Workspaces/M1-IPI/IPIWeb";
	private static final String BDD_LOGIN = "azerty";
	private static final String BDD_PASSWORD = "";
	private static final String BDD_DRIVER = "org.h2.Driver";
	
	public static JdbcUtils getInstance() {
		if (instance == null) {
			instance = new JdbcUtils();
		}
		return instance;
	}

	public Connection getConnection() throws Exception {

		Connection vConnection = null;
		try {
			Class.forName(BDD_DRIVER);
			vConnection = DriverManager.getConnection(BDD_URL, BDD_LOGIN, BDD_PASSWORD);
		} catch (SQLException e) {
			throw new Exception("Impossible de recuperer la connexion", e);
		} catch (ClassNotFoundException e) {
			throw new Exception("Impossible de charger le driver", e);
		}
		
		return vConnection;
	}
}